package com.yin.myproject.thread;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Eason
 * @create 2018-03-13 22:30
 **/
public class BlockingArrayTest {
    public static void main(String[] args){
//        final BlockingArray<Integer> blockingArray = new BlockingArray<>(10);
        final BlockingArrayWithCondition<Integer> blockingArray = new BlockingArrayWithCondition<Integer>(10);
        final AtomicInteger count = new AtomicInteger(0);
        for(int i = 0; i < 100; i ++){
            Thread t = new Thread(() -> {
                try {
                    blockingArray.put(count.incrementAndGet());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            t.start();
        }

        for(int i = 0; i < 100; i ++){
            Thread t = new Thread(() -> {
                try {
                    blockingArray.take();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            t.start();
        }

    }
}
